package io.itit.ecp.admin.provide.action.controller;

import io.itit.ecp.admin.provide.action.resp.MiniProgramResp;
import io.itit.ecp.admin.server.entity.MiniProgramEntity;
import io.itit.ecp.admin.server.service.IMiniProgramService;
import io.itit.grass.common.provide.action.resp.ResultResp;
import io.itit.grass.common.server.utils.ConvertUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 小程序首页管理
 */
@Api(tags = "小程序首页管理")
@RestController
@RequestMapping("/ecp-admin/miniProgram/homePage")
public class MiniProgramController {

    @Autowired
    private IMiniProgramService miniProgramService;

    @GetMapping("get")
    public ResultResp<MiniProgramResp> get(@RequestParam(defaultValue = "1") String id) {
        MiniProgramEntity miniProgram = miniProgramService.getById(id);
        return ResultResp.success(ConvertUtils.convert(miniProgram, MiniProgramResp.class));
    }

    @ApiOperation("编辑")
    @PostMapping("update")
    @RequiresPermissions("ecp-admin:miniProgramHomePage:update")
    public ResultResp<Boolean> update(@RequestBody MiniProgramEntity req) {
        return ResultResp.success(miniProgramService.saveOrUpdate(req));
    }

}
